
/**
 * 使用redux-thunk这个中间件，将方法就变成action
 * action的type值就是方法的名称
 */
import axios, { AxiosError } from "axios";
import {getShopcartListActionCreator} from '@/store/actions/shopcartAction'
export const getShopcartAsync=async(dispatch)=>{
    const result=await axios.get('http://www.zhaijizhe.cn:3006/shopcart/getShopcartData')
    console.log('result',result);
    dispatch(getShopcartListActionCreator(result.data))
}
/**
 * 编写更改商品数量的异步方法
 */
export const changeNumAsync=(arg)=>{
    console.log('-------changeNumAsync-------');
    console.log('arg',arg);
    return async function(dispatch){
        const result=await axios({
            method:'POST',
            url:'http://www.zhaijizhe.cn:3006/shopcart/changeNum',
            data:arg
        })
       if(result.data.code==200){
         dispatch(getShopcartAsync)
       }
    }
}
